﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AGrandVenture
{
    public class LootItem : GameObject
    {
        #region Declarations
        private int collisionRadius = 28;
        private bool destroyed;
        private InventoryItem inventoryItem;

        #endregion
        #region Enums

        #endregion

        #region Properties

        public bool Destroyed
        {
            get { return destroyed; }
            set { destroyed = value; }
        }

        public InventoryItem Item
        {
            get { return inventoryItem; }
            set { inventoryItem = Item; }
        }
        #endregion

        #region Public Methods
        public LootItem(UInt64 seed, Vector2 worldLocation)
        {

            //The greater totalPossibleItemTypes is the less chance of getting a non-gold drop
            //because all random numbers generated greater than totalPossibleItemTypes will only be gold
            int totalPossibleItemTypes = Enum.GetNames(typeof(InventoryItem.ItemType)).Length;
            
            //Add good/bad luck modifiers
            int badLuckModifier = Player.Character.TotalLuck < 6 ? Player.Character.TotalLuck : 0;
            int goodLuckModifier = Player.Character.TotalLuck > 8 ? (Player.Character.TotalLuck - 8) : 0;

            //Multiplying by three sets chance of gold/item to 66/33 chance
            int maxPossibleItemNumber = (totalPossibleItemTypes*3) + badLuckModifier - goodLuckModifier;

            //If maxPossible is less than totalPossible then they'll ONLY get some items - want to prevent that
            maxPossibleItemNumber = (maxPossibleItemNumber < totalPossibleItemTypes) ? totalPossibleItemTypes : maxPossibleItemNumber;

            //choose which itemtype to use
            int itemRoll = DiceRoll.D6;
            if (itemRoll == 6)
                inventoryItem = new MeleeWeaponItem(seed);
            else if (itemRoll == 5)
                inventoryItem = new ArmorItem(seed);
            else//TODO: Need to add gold, and other item types
            {
                inventoryItem = new ArmorItem(seed);
            }

            inventoryItem.Base.WorldLocation = worldLocation;

            inventoryItem.Base.CollisionRadius = collisionRadius;
        }
        #endregion
    }
}
